package com.yalemang.photovalut.base.widget

import android.annotation.SuppressLint
import android.content.Context
import android.util.AttributeSet
import android.view.MotionEvent
import android.widget.TextView
import com.yalemang.photovalut.res.R

@SuppressLint("AppCompatCustomView")
class CalculatorTextView : TextView {

    //按下时背景颜色
    private var downColor : Int = R.color.grey_20
    //其他时候背景颜色
    var defaultColor : Int = R.color.blue
        set(defaultColor) {
            init()
            field = defaultColor
        }

    private fun init() {
        setBackgroundColor(defaultColor)
    }

    constructor(context: Context?) : super(context)
    constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs)
    constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(
        context,
        attrs,
        defStyleAttr
    )
    constructor(
        context: Context?,
        attrs: AttributeSet?,
        defStyleAttr: Int,
        defStyleRes: Int
    ) : super(context, attrs, defStyleAttr, defStyleRes)


    @SuppressLint("ClickableViewAccessibility", "ResourceAsColor")
    override fun onTouchEvent(event: MotionEvent): Boolean {
        //判断是否是down事件
        if (MotionEvent.ACTION_UP == event.action){
            this.setBackgroundColor(defaultColor)
        }else{
            this.setBackgroundColor(downColor)
        }

        return super.onTouchEvent(event)
    }
}